package com.hmall.search.controller;

import com.hmall.api.dto.ItemDTO;
import com.hmall.common.domain.dto.PageDTO;
import com.hmall.search.domain.query.ItemPageQuery;
import com.hmall.search.service.IItemSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "搜索相关接口")
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class ItemSearchController {

    private final IItemSearchService searchService;

    @ApiOperation("搜索商品")
    @GetMapping("/list") //前端参数传递
    public PageDTO<ItemDTO> search(ItemPageQuery query) {
        return this.searchService.search(query);
    }

    @ApiOperation("过滤条件聚合查询")
    @PostMapping("/filters") //前端对象传递，添加@RequestBody！
    public Map<String, List<String>> filters(@RequestBody ItemPageQuery query) {
        return this.searchService.filters(query);
    }

    @ApiOperation("查询自动补全")
    @GetMapping("/suggestion")
    public List<String> suggestions(@RequestParam("key") String prefix) {
        return this.searchService.suggestions(prefix);
    }


}
